package com.wmg.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/*登录拦截器*/

public class LoginInterceptor implements HandlerInterceptor {

    public boolean preHandle(HttpServletRequest request,
                             HttpServletResponse response,
                             Object handler) throws Exception {
        if(request.getSession().getAttribute("user") == null){
           //无登录,重定向到登录页面
            System.err.println("----------------------登录---------------------");

            response.sendRedirect("/toLogin");
            return false;
        }else {
            //否则放行
            System.err.println("----------------------放行---------------------");
            return true;
        }
    }
}
